package com.jack.jetpackapp.activity

import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.library.GlobalViewModel
import com.jack.jetpackapp.R
import com.jack.jetpackapp.dialog.TestDialog
import com.jack.jetpackapp.expand.*
import com.jack.jetpackapp.viewmodel.UserModel
import com.jack.uikit.expand.*
import com.jack.uikit.utils.Logger
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.tvTest)
    private lateinit var tvTest: TextView

    private lateinit var userModel: UserModel

    private var levelType: Int = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        userModel = GlobalViewModel.get().getViewModel(UserModel::class.java)
        ViewBinder.get().init(this)
        ClickBinder.init(this)
        tvTest.text = "world"
        Logger.get().d(msg = "onCreate")

//        text.drawable = shapeDrawable {
//            radius = 30f
//            strokeWidth = 3
//            strokeColor = Color.GREEN
//            gradientType = GradientDrawable.Orientation.LEFT_RIGHT
//            gradientColors = arrayOf(Color.YELLOW, Color.RED).toIntArray()
//        }

        text.drawable = selectorDrawable {
            selectDrawable = shapeDrawable {
                radius = 30f
                strokeWidth = 3
                strokeColor = Color.GREEN
                gradientType = GradientDrawable.Orientation.LEFT_RIGHT
                gradientColors = arrayOf(Color.YELLOW, Color.RED).toIntArray()
            }
            unSelectDrawable = shapeDrawable {
                radius = 30f
                strokeWidth = 3
                strokeColor = Color.GREEN
                gradientType = GradientDrawable.Orientation.LEFT_RIGHT
                gradientColors = arrayOf(Color.RED, Color.YELLOW).toIntArray()
            }
        }
        tvViewModel.setOnClickListener {
            userModel.updateUserInfo("jack", 35)
            val intent = Intent(this, AnimatorActivity::class.java)
            startActivity(intent)
        }
//        text.setOnClickListener {
//            text.isSelected = !text.isSelected
//            dialogShow()
//        }

        edit.afterTextChanged {
            toast(it)
        }

        tvNavigation.signClick {
            start<com.zxf.navigation.activity.NavigationActivity>()
        }
        setLevelType(LevelType.TYPE_VIP)
    }

    private fun dialogShow() {
        showDialog(this) {
            onCancelListener = {
                toast("点击取消按钮")
            }
            onConfirmListener = {
                toast("点击确定按钮")
            }
            onViewCreated = {
                getView<TextView>(R.id.tvMsg)?.text = "这是一条测试弹窗消息"
            }
        }
    }

    private fun setLevelType(@LevelType type: Int) {
        levelType = type
        text.text = "注解$levelType"
    }

    @BindClick([R.id.tvTest, R.id.text])
    fun onClick(view: View) {
        if (view is TextView) {
            toast("msg=${view.text}")
        } else {
            toast("id=${view.id}")
        }
        val dialog = TestDialog(this)
        dialog.show()
    }
}